﻿using lso_2u_Web应用开发.Models.Database;
using System.Linq;

namespace lso_2u_Web应用开发.App_Code.Service
{
    public class UserService
    {
        private readonly DressWorkSystemContext _db;
        public UserService(DressWorkSystemContext dressWorkSystemContext)
        {
            _db = new DressWorkSystemContext();
        }

        public User Login(string phoneNumber, string password)
        {
            return _db.Users.FirstOrDefault(x => x.PhoneNumber == phoneNumber && x.Password == password);
        }

        public bool Register(User user)
        {
            var regUser = new User()
            {
                Name = user.Name,
                PhoneNumber = user.PhoneNumber,
                Password = user.Password,
            };

            _db.Users.Add(regUser);

            var row = _db.SaveChanges();
            if (row > 0)
            {
                return true;
            }

            return false;
        }

        public User GetInfoById(int id)
        {
            return _db.Users.FirstOrDefault(x => x.Id == id);
        }

    }
}
